package app.tools.encode;

import org.springframework.context.annotation.Bean;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.util.Base64;

//@Configuration
public class LoadEncode {
    @Bean
    public <T> void LoadEncode() throws ClassNotFoundException {
        Class<?> aClass = Class.forName("app.controller.MainController");
        Field[] fields = aClass.getDeclaredFields();
        for (Field field :
                fields) {
            Encode encode = field.getAnnotation(Encode.class);
            try {
                field.setAccessible(true);
                byte[] bytes = Base64.getEncoder().encode(field.get(String.class).toString().getBytes(encode.CodeType()));
                field.set(null, new String(bytes));
            } catch (IllegalAccessException | UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    }
}
